package com.zlz.server.controller;


import com.zlz.server.annotation.OperateLog;
import com.zlz.server.pojo.Department;
import com.zlz.server.pojo.RespBean;
import com.zlz.server.service.IDepartmentService;
import com.zlz.server.enums.OprLevel;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author efire
 * @since 2021-01-27
 */
@RestController
@RequestMapping("/system/basic/department")
public class DepartmentController {
    @Resource
    private IDepartmentService iDepartmentService;

    @ApiOperation("获取所有部门")
    @GetMapping("/")
    public RespBean getAllDepartments() {
        return RespBean.success(iDepartmentService.getAllDepartments());
    }

    @ApiOperation("添加部门")
    @PostMapping("/")
    @OperateLog(operationName = "添加部门", moduleName = "部门", level = OprLevel.LOW)
    public RespBean addDepartment(@RequestBody Department department) {
        return iDepartmentService.addDept(department);
    }

    @ApiOperation("删除部门")
    @DeleteMapping("/{id}")
    @OperateLog(operationName = "删除部门", moduleName = "部门", level = OprLevel.HIGH)
    public RespBean delDepartmentById(@PathVariable("id") Long id) {
        return iDepartmentService.delDepartmentById(id);
    }
}
